package com.xl.game.tool;

import android.content.*;
import android.view.*;
import android.graphics.drawable.*;
import android.view.animation.*;

public class ViewTool
{
	//加载布局成view
	public static View getView(Context context,int id)
	{
		LayoutInflater factory =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
	//LayoutInflater factory = LayoutInflater.from(context);
	return  factory.inflate(id, null);
	}
	
	//通过文件名加载drawable
	public static Drawable getDrawable(Context context,String name)
	{
		int id = context.getResources().getIdentifier(name,"drawable",  context.getPackageName());  
		return context.getResources().getDrawable(id); 
	}
	/**
	 * View渐隐动画效果
	 *
	 */
	private void setHideAnimation( View view, int duration ){
		AlphaAnimation mHideAnimation= null;
		if( null == view || duration<0 ){
			return;
		}
		if( null != mHideAnimation ){
			mHideAnimation.cancel( );
		}
		mHideAnimation = new AlphaAnimation(1.0f, 0.0f);
		mHideAnimation.setDuration( duration );
		mHideAnimation.setFillAfter( true );
		view.startAnimation( mHideAnimation );
	}
	/**
	 * View渐显动画效果
	 *
	 */
	private void setShowAnimation( View view, int duration ){
		AlphaAnimation mShowAnimation= null;
		if( null == view || duration<0 ){
			return;
		}
		if( null != mShowAnimation ){
			mShowAnimation.cancel( );
		}
		mShowAnimation = new AlphaAnimation(0.0f, 1.0f);
		mShowAnimation.setDuration( duration );
		mShowAnimation.setFillAfter( true );
		view.startAnimation( mShowAnimation );
	}
	
}
